<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="macOS上使用踩坑DB2记录, 双的鱼 双的鱼博客 hexo博客 个人博客">
    <meta name="description" content="双的鱼博客，记录我的学习和感想">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer" />
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>macOS上使用踩坑DB2记录 | 双的鱼博客</title>
    <link rel="icon" type="image/png" href="/images/logo.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="双的鱼博客" type="application/atom+xml">
</head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/images/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">双的鱼博客</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/weibo" class="waves-effect waves-light">
      
      <i class="fa fa-comment" style="zoom: 0.6;"></i>
      
      <span>微博</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/album" class="waves-effect waves-light">
      
      <i class="fa fa-camera-retro" style="zoom: 0.6;"></i>
      
      <span>相册</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/images/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">双的鱼博客</div>
        <div class="logo-desc">
            
            双的鱼博客，记录我的学习和感想
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/weibo" class="waves-effect waves-light">
			
			    <i class="fa-fw fa fa-comment"></i>
			
			微博
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/album" class="waves-effect waves-light">
			
			    <i class="fa-fw fa fa-camera-retro"></i>
			
			相册
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('请输入访问本文章的密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('/gallery/DB2.png')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">macOS上使用踩坑DB2记录</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
        height: auto;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
        max-height: calc(100vh - 10rem);
    }

    #toc-content ol {
        padding-left: 10px;
        overflow: auto;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/database/">
                                <span class="chip bg-color">database</span>
                            </a>
                        
                            <a href="/tags/mac/">
                                <span class="chip bg-color">mac</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E6%8A%80%E6%9C%AF/" class="post-category">
                                技术
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2023-12-13
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    1.4k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    5 分
                </div>
                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>由于项目需求，需要对接很多种类的数据库，包括一些平时比较冷门甚至听都没听过的，而开发环境是MAC的M2，开发语言是Golang。</p>
<p>不得不说，这个开发环境对于很多数据库对接是很有难度的，首先很多数据库不支持在ARM架构系统上安装，而且Golang的数据库驱动除了主流的几个数据库之外，支持度并不是很好，很多甚至还不支持，就算支持也存在arm系统的问题，总的来说有点痛苦，踩了很多坑。</p>
<p>以下就记录下对接BD2的时候遇到的问题。</p>
<blockquote>
<p>DB2就是IBM开发的一种大型关系型数据库平台。</p>
</blockquote>
<h2 id="一、安装"><a href="#一、安装" class="headerlink" title="一、安装"></a>一、安装</h2><p>安装就不说了，不要在mac M1 M2上安装，ibm官方只提供mac intel的安装包，docker镜像也都是amd系统的，在arm系统上运行会有问题。</p>
<p>所以我在公司申购了一台linux服务器专门用来支持各种开发环境用。</p>
<p>安装就略过了，直接docker安装即可。</p>
<blockquote>
<p>直接贴上地址：<a target="_blank" rel="noopener" href="https://www.yuque.com/shuangyu-rcged/network/bb7p905taxmm56sh">https://www.yuque.com/shuangyu-rcged/network/bb7p905taxmm56sh</a></p>
</blockquote>
<h2 id="二、安装Go驱动"><a href="#二、安装Go驱动" class="headerlink" title="二、安装Go驱动"></a>二、安装Go驱动</h2><p>IBM有提供针对Golang语言的DB2数据库驱动：<a target="_blank" rel="noopener" href="https://github.com/ibmdb/go_ibm_db">https://github.com/ibmdb/go_ibm_db</a></p>
<p>其安装步骤如下：<br>1、下载golang驱动包，使用下面任一指令即可，项目中有mod模块的话就更方便了，直接同步下依赖就行</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">go get <span class="token operator">-</span>d github<span class="token punctuation">.</span>com/ibmdb/go_ibm_db
go install github<span class="token punctuation">.</span>com/ibmdb/go_ibm_db/installer@latest
go install github<span class="token punctuation">.</span>com/ibmdb/go_ibm_db/installer@v0<span class="token punctuation">.</span>4<span class="token punctuation">.</span>5</code></pre>

<p>2、安装odbc驱动<br>除了下载安装golang程序驱动包之外，DB2的使用还需要安装odbc的驱动并进行一些相关配置</p>
<p>首先，设置驱动下载地址的环境变量，安装的时候会自动去这个地址下载，或者你也可以自己下载下来放到自己指定的目录</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">export IBM_DB_DOWNLOAD_URL=https:<span class="token operator">/</span><span class="token operator">/</span>public<span class="token punctuation">.</span>dhe<span class="token punctuation">.</span>ibm<span class="token punctuation">.</span>com/ibmdl/export/pub/software/<span class="token keyword">data</span><span class="token operator">/</span>db2/drivers/odbc_cli/v11<span class="token punctuation">.</span>5<span class="token punctuation">.</span>4/macos64_odbc_cli<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz</code></pre>

<p>下一步，如果你已经手动下载了的话就不用进行了，需要自动下载就进行下一步<br>进入到第一步安装的golang驱动包里面的installer目录，比如我的是<code>/Users/jyj/goproject/pkg/mod/github.com/ibmdb/go_ibm_db@v0.4.5/installer</code>，里面有安装脚本<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702433310162-6b49f2bf-c220-418c-a330-cd4ec9179946.png#averageHue=%23fafafa&clientId=ua920b183-5d70-4&from=paste&height=175&id=u153ff064&originHeight=350&originWidth=668&originalType=binary&ratio=2&rotation=0&showTitle=false&size=52087&status=done&style=none&taskId=uae4e0fbb-9542-483d-8dac-1dca3a1c6bb&title=&width=334" alt="image.png"></p>
<p>然后执行这条指令，自动下载驱动包：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">go run setup<span class="token punctuation">.</span>go</code></pre>

<p>这时执行完之后的目录，下载并解压完成驱动包<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702433430356-4cef214c-c037-423a-955e-156be18e16a6.png#averageHue=%23faf4f4&clientId=ua920b183-5d70-4&from=paste&height=190&id=u327d1628&originHeight=380&originWidth=742&originalType=binary&ratio=2&rotation=0&showTitle=false&size=80117&status=done&style=none&taskId=ua89ddde1-6bda-48e6-a257-bc9e6753b36&title=&width=371" alt="image.png"></p>
<p>最后还要设置环境变量<br>可以手动设置：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">export IBM_DB_HOME=<span class="token operator">/</span>home/uname/go/src/github<span class="token punctuation">.</span>com/ibmdb/clidriver
export CGO_CFLAGS=<span class="token operator">-</span>I<span class="token variable">$IBM_DB_HOME</span><span class="token operator">/</span>include
export CGO_LDFLAGS=<span class="token operator">-</span>L<span class="token variable">$IBM_DB_HOME</span><span class="token operator">/</span>lib
export DYLD_LIBRARY_PATH=<span class="token variable">$DYLD_LIBRARY_PATH</span>:<span class="token variable">$IBM_DB_HOME</span><span class="token operator">/</span>lib</code></pre>

<p>也可以运行脚本自动设置，在installer目录下：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">source setenv<span class="token punctuation">.</span>sh</code></pre>

<p><strong>注意：</strong><br>但是，强烈建议将环境变量的设置放到’<strong>~/.zshrc</strong>‘中，因为写代码的时候编辑器可能会读取不到环境变量</p>
<p>整个驱动安装大致就是以上步骤了，其它windows、linux系统的看官方的github就可以了</p>
<h2 id="三、问题"><a href="#三、问题" class="headerlink" title="三、问题"></a>三、问题</h2><p>安装完成，那剩下的就是开跑验证了，连接代码参考官方给出的示例：</p>
<pre class="language-go" data-language="go"><code class="language-go"><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
    <span class="token string">"database/sql"</span>
    <span class="token string">"fmt"</span>
    <span class="token boolean">_</span> <span class="token string">"github.com/ibmdb/go_ibm_db"</span>
<span class="token punctuation">)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
    con <span class="token operator">:=</span> <span class="token string">"HOSTNAME=host;DATABASE=name;PORT=number;UID=username;PWD=password"</span>
    db<span class="token punctuation">,</span> err <span class="token operator">:=</span> sql<span class="token punctuation">.</span><span class="token function">Open</span><span class="token punctuation">(</span><span class="token string">"go_ibm_db"</span><span class="token punctuation">,</span> con<span class="token punctuation">)</span>
    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">&#123;</span>
        fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span>
    <span class="token punctuation">&#125;</span>
    db<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">&#125;</span></code></pre>

<p>1、github.com/ibmdb/go_ibm_db@v0.4.5/api/api_unix.go:14:11: fatal error: ‘sqlcli1.h’ file not found<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702444918309-c59ab98b-1173-4dda-923b-effd4979bebc.png#averageHue=%23434242&clientId=ua920b183-5d70-4&from=paste&height=89&id=uf2c840ac&originHeight=178&originWidth=1850&originalType=binary&ratio=2&rotation=0&showTitle=false&size=38248&status=done&style=none&taskId=u03b4ef23-20e3-4209-ba42-50a6c7a2ce3&title=&width=925" alt="image.png"><br>在goland里面运行可能会报这个错误，这是因为没有读取到环境变量，而我在goland的运行配置里面加上这些驱动的环境变量也没有生效，所以上面我建议将驱动的环境变量配置到系统文件’~/.zshrc’中，作为全局，可以取消这个报错<br>如果你一开始就用命令行直接运行则没问题</p>
<p>另外，还可能会有这个提示：<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702438060084-dd28a741-dcf7-429d-85cd-fb215fa48f58.png#averageHue=%23e9e9e8&clientId=ua920b183-5d70-4&from=paste&height=77&id=u42672c70&originHeight=154&originWidth=712&originalType=binary&ratio=2&rotation=0&showTitle=false&size=20050&status=done&style=none&taskId=u0a87c6ad-5995-4546-9497-bf46b88cae7&title=&width=356" alt="image.png"><br>很明显是’CGO_CFLAGS’这个环境变量的问题，按照提示修改成这样</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">export CGO_CFLAGS=<span class="token string">"-I<span class="token variable">$IBM_DB_HOME</span>/include -O0 -g"</span></code></pre>

<p>当然，上面这两个错误基本是在使用goland编辑器运行程序的时候会报错，因为想要开发调试方便，所以必须要解决</p>
<p>2、building for macOS-arm64 but attempting to link with file built for macOS-x86_64<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702438434375-4c66f2e8-98b9-43ee-b218-2f72e6190649.png#averageHue=%23373535&clientId=ua920b183-5d70-4&from=drop&id=u9209cd97&originHeight=1820&originWidth=2632&originalType=binary&ratio=2&rotation=0&showTitle=false&size=803208&status=done&style=none&taskId=u90125e41-842d-4b25-9c31-3a4dc537f65&title=" alt="截屏2023-12-13 11.32.33.png"><br>根据错误描述可知，这个驱动其实是不兼容macOS-arm64的，在我将项目部署到linux-amd64上运行成功之后，验证了这一事实的准确性。</p>
<p>那么如何在macOS-arm64上跑起来呢？</p>
<p>查询资料有说是用Rosetta 2模拟x86架构去跑的：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">arch <span class="token operator">-</span>x86_64 go run main<span class="token punctuation">.</span>go</code></pre>

<p>决定试一试，经过一番试验之后，得出结论，当前arm64系统安装的golang版本也是arm架构的，那么我再安装一个amd64版本的golang，用它去跑程序是不是就行了。</p>
<p>首先，在Rosetta总安装brew：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">arch <span class="token operator">-</span>x86_64 <span class="token operator">/</span>bin/bash <span class="token operator">-</span>c <span class="token string">"<span class="token function">$<span class="token punctuation">(</span>curl <span class="token operator">-</span>fsSL https:<span class="token operator">/</span><span class="token operator">/</span>raw<span class="token punctuation">.</span>githubusercontent<span class="token punctuation">.</span>com/Homebrew/install/HEAD/install<span class="token punctuation">.</span>sh<span class="token punctuation">)</span></span>"</span></code></pre>

<p>然后安装golang，放心安装，不会影响之前安装的golang环境：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell">arch <span class="token operator">-</span>x86_64 brew install go@1<span class="token punctuation">.</span>19</code></pre>

<p>因为在命令行下运行会涉及到环境变量的修改等问题，再次借助goland可以很方便切换运行环境，并成功运行，可以达到我在mac-arm64方便开发调试的目的：</p>
<pre class="language-powershell" data-language="powershell"><code class="language-powershell"><span class="token operator">/</span><span class="token operator">/</span> 命令行运行会报错
arch <span class="token operator">-</span>x86_64 <span class="token operator">/</span>usr/local/Cellar/go@1<span class="token punctuation">.</span>19/1<span class="token punctuation">.</span>19<span class="token punctuation">.</span>13/libexec/bin/go run main<span class="token punctuation">.</span>go</code></pre>

<p>在这里切换goroot：<br><img src="https://cdn.nlark.com/yuque/0/2023/png/115159/1702445523348-1d2a1131-5045-468c-810f-17a3d7611f36.png#averageHue=%23ededed&clientId=ua920b183-5d70-4&from=drop&id=u06583efe&originHeight=1442&originWidth=1964&originalType=binary&ratio=2&rotation=0&showTitle=false&size=275078&status=done&style=none&taskId=u182891e0-4817-4c60-8782-e11efef22d3&title=" alt="截屏2023-12-13 13.31.38.png"></p>
<p>切换完再运行程序就顺利跑起来了，唯一有缺憾的是切换成amd64的golang的话，在arm64下的goland中无法使用debug功能，只能通过打印的方式进行调试了。</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">JIANG XIAOFAN</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://shuangdeyu.gitee.io/2023/12/13/macos-shang-shi-yong-cai-keng-db2-ji-lu/">https://shuangdeyu.gitee.io/2023/12/13/macos-shang-shi-yong-cai-keng-db2-ji-lu/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">JIANG XIAOFAN</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/database/">
                                    <span class="chip bg-color">database</span>
                                </a>
                            
                                <a href="/tags/mac/">
                                    <span class="chip bg-color">mac</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg4.jpeg") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'Cu0yGDQXYEoC2BMFqoMyqSK1-gzGzoHsz',
        appKey: 'PYfyCYN5lI59X5Rczd5IGls5',
        notify: 'false' === 'true',
        verify: 'true' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '20',
        lang: 'zh-cn',
        placeholder: 'hi，留个脚印吧'
    });
</script>

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2023/12/15/go-lian-jie-oracle-godror-qu-dong-shi-yong-ji-lu/">
                    <div class="card-image">
                        
                        <img src="/gallery/godror.png" class="responsive-img" alt="Go连接Oracle，godror驱动使用记录">
                        
                        <span class="card-title">Go连接Oracle，godror驱动使用记录</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2023-12-15
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%8A%80%E6%9C%AF/" class="post-category">
                                    技术
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Go/">
                        <span class="chip bg-color">Go</span>
                    </a>
                    
                    <a href="/tags/database/">
                        <span class="chip bg-color">database</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2023/12/08/k8s-xue-xi-bi-ji-1-kubeadm-an-zhuang-k8s/">
                    <div class="card-image">
                        
                        <img src="/gallery/k8s-1.jpg" class="responsive-img" alt="k8s学习笔记(1)—kubeadm安装k8s">
                        
                        <span class="card-title">k8s学习笔记(1)—kubeadm安装k8s</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2023-12-08
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%8A%80%E6%9C%AF/" class="post-category">
                                    技术
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/docker/">
                        <span class="chip bg-color">docker</span>
                    </a>
                    
                    <a href="/tags/k8s/">
                        <span class="chip bg-color">k8s</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="113118807"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <span id="year">2019</span>
            <a href="/about" target="_blank">JIANG XIAOFAN</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">107k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>















    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

	
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
